package com.study.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author MI
 * @version 1.0
 * @date 2020/10/18 21:32
 */
@Component
public class RequestOriginParserDefinition implements RequestOriginParser {

    //区分来源，通过request获取来源标识。
    //然后交给流控标识匹配
    @Override
    public String parseOrigin(HttpServletRequest request) {
        String serviceName = request.getParameter("serviceName");
        if (StringUtils.isBlank(serviceName)) {
            throw new RuntimeException("serviceNmae is null");
        }
        return serviceName;
    }
}
